import { FrameTimer } from "../../../../../com/gengine/core/frame/FrameTimer";
import { TimerType } from "../../../../../com/gengine/core/frame/TimerType";
import { ShadowPlayer } from "./ShadowPlayer";
import { ObjectPool } from "../../../../../com/gengine/utils/pools/ObjectPool";
import { RolePlayerCopy } from "./RolePlayerCopy";
import { LGXBMap } from "../map/LGXBMap";
import { DirectionType } from "../../../scene/modle/data/DirectionType";
import { West } from "../../../../../DirectionType/West";
import { North } from "../../../../../DirectionType/North";
type int = number;
//class ShadowListManager
    
    export  class ShadowListManager
    {
        constructor()
        {
            
            this._timer = new FrameTimer();
            this.boxes = new Object /* flash.display.Sprite */();
            var loc1;
            this.boxes.mouseEnabled = loc1 = false;
            this.boxes.mouseChildren = loc1;
            this._timer.addListener(TimerType.ENTERFRAME, this.onEnterFrameHandler);
            this._timer.repeatCount = Number.MAX_VALUE;
            return;
        }

        /* internal  */onEnterFrameHandler(arg1: FrameTimer): void
        {
            var loc3=null;
            var loc1=this.boxes.numChildren;
            if (loc1 == 0) 
            {
                this._timer.stop();
                return;
            }
            var loc2=[];
            var loc4=0;
            while (loc4 < loc1) 
            {
                loc3 = this.boxes.getChildAt(loc4) as ShadowPlayer;
                loc3.alpha = loc3.alpha - 0.03;
                if (loc3.alpha <= 0.01) 
                {
                    loc2.push(loc3);
                }
                ++loc4;
            }
            loc1 = loc2.length;
            loc4 = 0;
            while (loc4 < loc1) 
            {
                loc3 = loc2[loc4];
                this.boxes.removeChild(loc3);
                ObjectPool.disposeObject(loc3, ShadowPlayer);
                ++loc4;
            }
            return;
        }

        public addEffect(arg1: Object, arg2: Array<any>, arg3: RolePlayerCopy): void
        {
            var loc8=NaN;
            var loc9=NaN;
            var loc10=null;
            var loc11=null;
            var loc12=null;
            if (!arg3.stage) 
            {
                return;
            }
            arg3.parent.addChild(this.boxes);
            var loc1=arg2.length;
            var loc2=int(Math.sqrt(loc1) * 13);
            var loc3=0;
            var loc4=arg1;
            var loc5=10;
            var loc6=[];
            while (loc3 < loc1) 
            {
                if ((loc10 = arg2[loc3]).x != loc4.x) 
                {
                    if (loc10.y == loc4.y) 
                    {
                        loc5 = this.getPointsByY(loc5, loc6, loc4, loc10, loc2);
                    }
                }
                else 
                {
                    loc5 = this.getPointsByX(loc5, loc6, loc4, loc10, loc2);
                }
                loc4 = loc10;
                ++loc3;
            }
            var loc7=loc6.length;
            loc8 = 0.55;
            loc9 = (1 - loc8) / loc7;
            loc3 = 0;
            while (loc3 < loc7) 
            {
                loc11 = loc6[loc3];
                (loc12 = ObjectPool.getObject(ShadowPlayer, arg3)).x = loc11.x;
                loc12.y = loc11.y;
                loc12.updateDirect(loc11.direct);
                loc12.alpha = loc8 + loc9 * loc3;
                this.boxes.addChild(loc12);
                ++loc3;
            }
            if (!this._timer.running) 
            {
                this._timer.start();
            }
            return;
        }

        /* internal  */getPointsByX(arg1: int, arg2: Array<any>, arg3: Object, arg4: Object, arg5: int): number
        {
            var loc1=LGXBMap.instance.changeTileToPixelPoint(arg3);
            var loc2;
            var loc3;
            var loc4=(loc3 = (loc2 = LGXBMap.instance.changeTileToPixelPoint(arg4)).x > loc1.x ? 1 : -1) > 0 ? DirectionType.East : West;
            var loc5=new PointInfo(loc1.x + arg1 * loc3, loc1.y, loc4);
            arg2.push(loc5);
            var loc6=(loc2.x - loc1.x) * loc3 - arg1;
            var loc7=arg5;
            var loc8=loc5;
            while (loc7 <= loc6) 
            {
                loc8 = new PointInfo(loc8.x + arg5 * loc3, loc8.y, loc4);
                arg2.push(loc8);
                loc7 = loc7 + arg5;
            }
            arg1 = loc7 - loc6;
            return arg1;
        }

        /* internal  */getPointsByY(arg1: int, arg2: Array<any>, arg3: Object, arg4: Object, arg5: int): number
        {
            var loc1=LGXBMap.instance.changeTileToPixelPoint(arg3);
            var loc2;
            var loc3;
            var loc4=(loc3 = (loc2 = LGXBMap.instance.changeTileToPixelPoint(arg4)).y > loc1.y ? 1 : -1) > 0 ? DirectionType.South : North;
            var loc5=new PointInfo(loc1.x, loc1.y + arg1 * loc3, loc4);
            arg2.push(loc5);
            var loc6=(loc2.y - loc1.y) * loc3 - arg1;
            var loc7=arg5;
            var loc8=loc5;
            while (loc7 <= loc6) 
            {
                loc8 = new PointInfo(loc8.x, loc8.y + arg5 * loc3, loc4);
                arg2.push(loc8);
                loc7 = loc7 + arg5;
            }
            arg1 = loc7 - loc6;
            return arg1;
        }

        public static /* const */instance: ShadowListManager=new ShadowListManager();

        /* internal */ /* var */_timer: FrameTimer;

        /* internal */ /* var */boxes: Object /* flash.display.Sprite */;
    }
}


class PointInfo extends Object
{
    public PointInfo(arg1: int, arg2: int, arg3: int)
    {
        super();
        this.x = arg1;
        this.y = arg2;
        this.direct = arg3;
        return;
    }

    public /* var */x: int;

    public /* var */y: int;

    public /* var */direct: int;
